package com.qst.action.TestPersonnel;

import com.qst.BaseServlet;
import com.qst.ExamException;
import com.qst.RequestUtil;
import com.qst.WebUtil;
import com.qst.entity.TestPersonnel;
import com.qst.service.TestPersonnelService;
import com.qst.service.impl.ServiceFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//@WebServlet("/testPersonnel/delete.action")
public class DeleteServlet extends BaseServlet {
    private TestPersonnelService testPersonnelService = ServiceFactory.getService(TestPersonnelService.class);
    @Override
    protected void doAction(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取学生id
        int id = RequestUtil.getInt(req, "id");
        try {
            TestPersonnel testPersonnel = testPersonnelService.deleteTestPersonnel(id);
            WebUtil.forward(req, resp, "/testPersonnel/list.action?tid=" + testPersonnel.getTeamId());
        } catch (ExamException ex) {
            ex.printStackTrace();
            addError(req, ex.getMessage());
            WebUtil.forward(req, resp, "/testPersonnel/view.action?id=" + id);
        }
    }
}
